const express = require("express");
const router = express.Router();
const mongoose = require("mongoose");

// 获取 schema
const { Schema } = mongoose;
const url = "mongodb://127.0.0.1:27017/shopApp";
mongoose.connect(url)
    .then(() => console.log("链接成功数据库"))
    .catch(err => console.error("连接数据库失败:", err));

const DetailData = mongoose.model("getDetail");

// 删除数据
router.post("/delData", async (req, res, next) => {
    let { _id } = req.body;
    try {
        const delData = await DetailData.find({});
        console.log(delData);
        let arr = delData

        let resdata = await DetailData.deleteOne({ _id });
        res.status(200).json(
            {
                msg: "删除成功",
                code: 200,
                data: resdata
            }
        )

    } catch (error) {
        next(error);
    }

});

module.exports = router;